package com.gxc.xor;

/**
 * Created by ASD on 2022/12/21.
 */
public class SelectTwo {

    public static void main(String[] args) {
        int[] arr = new int[] {4,4,3,7,7,7,7, 9};
        int[] addTime = addTime(arr);
        System.out.println(addTime[0]);
        System.out.println(addTime[1]);
    }

    private static int[] addTime(int[] arr) {
        int j = 0;
        for (int i = 0; i < arr.length; i++) {
            j ^= arr[i];
        }
        //j = a^b
        int rightOne = computeRightOne(j);

        int a = 0;
        for (int i : arr) {
            if ((i & rightOne) == rightOne) {
                a ^=i;
            }
        }
        int b = j^a;
        int[] result = new int[2];
        result[0] = a;
        result[1] = b;
        return result;
    }

    //计算最右边的1
    private static int computeRightOne(int i) {
        return i &(~i+1);
    }


}
